
$(function () {
	var id=GetQueryString("id");
	vm.workOrderInfo(id);
	vm.workOrderContentInfo(id);
	if (vm.cexWorkOrder.statue!=2&&vm.cexWorkOrder.statue!=3) {
		$(".forComment").show();
	}else {
		$(".forComment").hide();
	}
	
	
});
$("#image").change(function() {
	var $file = $(this);
	var objUrl = $file[0].files[0];
	// 获得一个http格式的url路径:mozilla(firefox)||webkit or chrome
	var windowURL = window.URL || window.webkitURL;
	// createObjectURL创建一个指向该参数对象(图片)的URL
	var dataURL;
	dataURL = windowURL.createObjectURL(objUrl);
	$("#imageview").attr("src", dataURL);
});
var vm = new Vue({
	el:'#rrapp',
	data:{
		cexWorkOrder: {},
		cexWorkOrderContents:[],
		cexWorkOrderContent:{},
	},
	methods: {
		workOrderInfo:function(id){
			
			$.ajax({
				async : false,
				type: "POST",
			    url: "../cexworkorder/oneInfo/"+id,
			    success: function(r){
					if(r.code == 0){
						vm.cexWorkOrder=r.cexWorkOrder;
					}else{
						alert(r.msg);
					}
				}
			});
		},
		workOrderContentInfo:function(id){
			$.ajax({
				type: "POST",
			    url: "../cexworkordercontent/ListByWorkOrderId/"+id,
			    dataType : "json",
			    success: function(r){
					if(r.code == 0){
					
						vm.cexWorkOrderContents=r.cexWorkOrderContentResult;
					}else{
						alert(r.msg);
					}
				}
			});
		},
		saveworkOrderContentAdmin:function(){

			
			vm.cexWorkOrderContent.cexWorkOrderId=vm.cexWorkOrder.id;
			if (vm.cexWorkOrderContent.content==null||vm.cexWorkOrderContent.content=="") {
				alert("请填写补充问题");
			} else {
				$.ajax({
					type : "POST",
					url : "../cexworkordercontent/saveAdmin",
					contentType : "application/json",
					data : JSON.stringify(vm.cexWorkOrderContent),
					success : function(r) {
						if (r.code === 0) {
							var location = $("input[name='image']").val();
							if (location==null||location=="") {}
							else {

								
								$
										.ajaxFileUpload({
											async : false,
											url : "../cexworkordercontent/WordOrderContentImage/"+r.cexWorkOrderContent.id, // 用于文件上传的服务器端请求地址
											secureuri : false, // 是否需要安全协议，一般设置为false
											fileElementId : 'image', // 文件上传域的ID
											dataType : 'json', // 返回值类型
																// 一般设置为json
											success : function(
													data,
													status) // 服务器成功响应处理函数
											{

											},
											error : function(
													data,
													status,
													e)// 服务器响应失败处理函数
											{

											}
										})
							
								
							}
							window.location.reload();
						} else {
							alert(r.msg);
						}
					}
				});
			}
			
		
		},
		closeWordOrder:function(){
			
			vm.cexWorkOrder.statue=2;
			$.ajax({
				type : "POST",
				url : "../cexworkorder/update",
				contentType : "application/json",
				data : JSON.stringify(vm.cexWorkOrder),
				success : function(r) {
					if (r.code === 0) { 
						window.location.reload();
					} else {
						alert(r.msg);
					}
				}
			});
		},
		image : function() {
			var location = $("input[name='image']").val();
			var point = location.lastIndexOf(".");

			var type = location.substr(point);
			if (type == ".jpg" || type == ".JPG" || type == ".png") {

				var objUrl = $("#image")[0].files[0];

				// 获得一个http格式的url路径:mozilla(firefox)||webkit or chrome
				var windowURL = window.URL || window.webkitURL;
				// createObjectURL创建一个指向该参数对象(图片)的URL
				var dataURL;
				dataURL = windowURL.createObjectURL(objUrl);
				$("#imageview").attr("src", dataURL);
			}
			//

		}
	}
});